# encoding: utf-8
from flask import request, g
from common.utils.jwt_util import verify_jwt


def jwt_authentication():
    g.account = None
    g.user_id = None
    g.is_refresh = False
    # 获取请求头中的token
    token = request.headers.get('Authorization')
    if token is not None and token.startswith('Bearer '):
        token = token[7:]
        # 验证token
        payload = verify_jwt(token)

        if payload is not None:
            # 将荷载信息保存到g对象中 token:account、到期时间     refresh_token:account、到期时间、is_refresh
            g.account = payload.get('account')
            g.user_id = payload.get('user_id')
            g.is_refresh = payload.get('is_refresh', False)



